<?php

/**
 * @application Automatical Judging System
 * @author deltamaster
 * @copyright Softrank Research Center
 * @version 2.0.0.0
 */

//require_once "./include/common.inc.php";

function VerifyUsername($str)
{
    if (strlen($str) > 16 || strlen($str) < 4) return false;
    if (!preg_match("/^[0-9A-Za-z_]+$/", $str)) return false;
    global $db,$pre;
	//echo $sql ="SELECT * FROM `{$pre}userinfo_basic` WHERE `username`='{$str}'";
    $query = $db->query("SELECT * FROM `{$pre}userinfo_basic` WHERE `username`='{$str}'");
    if ($db->num_rows($query)) return false; //Can not be used
    else  return true; //Can be used
}

function VerifyLoginUsername($str)
{
    if (strlen($str) > 16 || strlen($str) < 4) return false;
    if (!preg_match("/^[0-9A-Za-z_]+$/", $str)) return false;
    return true;
}

function VerifyPassword($str)
{
    if (strlen($str) > 16 || strlen($str) < 4 || preg_match("/[\'\"\<\>\(\)]/", $str)) return false;
    return true;
}

function VerifyStudentId($str)
{
	if (preg_match("/\\d{8}/", $str)) return true;
	else return false;
}

function VerifyRealName($str)
{
    if (!preg_match("/^[\x80-\xff]+$/", $str)) return false;
    return true;
}

function VerifyEmail($str)
{
    if (!preg_match("/^([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})$/", $str)) return false;
    return true;
}

function VerifyMobile($str)
{
    if (!preg_match("/^\d{11}$/", $str)) return false;
    return true;
}

function VerifyTime($timestr)
{
    if (!preg_match("/\b(\d{4})\s*[-\/.,]\s*(\d{1,2})\s*[-\/.,]\s*(\d{1,2})\b/", $timestr)) return false;
    if (!preg_match("/\b(\d{1,2})\s*[:��]\s*(\d{1,2})\s*[:��]\s*(\d{1,2})\b/", $timestr)) return false;
    return true;
}

function VerifyGroupName($str)
{
    if (!preg_match("/^[^<>\?&'\"]{2,30}$/", $str)) return false;
    return true;
}

function VerifyCommon($str)
{
	if (!preg_match("/^[^<>\?&'\"]{1,400}$/", $str)) return false;
    return true;
}

?>